package previous.Test_0322;

import java.util.*;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Solution {
    //最大数
    public String largestNumber(int[] nums) {
          int n=nums.length;
          String[] s=new String[n];
        for (int i = 0; i < n; i++) {
            s[i]=" "+nums[i];
        }
        Arrays.sort(s,(a,b)->
        {
           return (a + b).compareTo(b + a);
        });
        StringBuilder s1=new StringBuilder();
        for (String x:s) {
            s1.append(x);
        }
        if(s1.charAt(0)=='0') return "0";
        return s1.toString();
    }
    //将数组减半和最少操作数
    public int halveArray(int[] nums) {
          double sum=0;
          int n=nums.length;
        PriorityQueue<Double> q=new PriorityQueue<>((a,b)->b.compareTo(a));
        for (int i = 0; i < n; i++) {
            sum+=nums[i];
            q.offer((double)nums[i]);
        }
        sum=sum/2;
        int count=0;
        while(sum>0){
            for (int i = 0; i <n ; i++) {
                double t=q.poll()/2.0;
                sum-=t;
                count++;
            }
        }
        return count;
    }
    //火星词典

}
